package com.zhentao;

import com.baomidou.mybatisplus.annotation.DbType;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.zhentao.market.ChargeMarketFeignApi;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Date;

/**
 * @ClassName: ChargeUserApplication
 * @Author: 振涛教育_Q
 * @Date: 2024/12/17 9:02
 */
@SpringBootApplication
@MapperScan("com.zhentao.mapper")
@EnableDiscoveryClient
@RefreshScope
@EnableAsync // 开启异步调用
@EnableScheduling // 开启定时任务
@EnableFeignClients(clients = {ChargeMarketFeignApi.class})
public class ChargeUserApplication {
    public static void main(String[] args) {
        SpringApplication.run(ChargeUserApplication.class, args);
    }
    @Bean
    public MetaObjectHandler metaObjectHandler(){
        MetaObjectHandler metaObjectHandler = new MetaObjectHandler() {
            @Override
            public void insertFill(MetaObject metaObject) {
                this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
            }

            @Override
            public void updateFill(MetaObject metaObject) {
                this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
            }
        };
        return metaObjectHandler;
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
